package guoanmaker.operator.business.controller;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.service.OperatorHomePageServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_HELP)
public class OperatorHomePageController {

	@Autowired
	private  AjaxJson ajaxJson;
	
	@Autowired
	private  OperatorHomePageServiceInterface operatorHomePageServiceInterface;
	
	@ApiOperation(value = "查询用户注册总数---分组查询   app   pc  注册数量--服务商注册数量-----日活跃数量    app活跃数量    pc活跃 ", 
			notes = "查询用户注册总数---分组查询   app   pc  注册数量--服务商注册数量-----日活跃数量    app活跃数量    pc活跃 ")
	@RequestMapping(value = "/userRegistrationInformation",method = RequestMethod.POST)
	public AjaxJson userRegistrationInformation(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(
					operatorHomePageServiceInterface.userRegistrationInformation());
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "每日注册量查询", notes = "每日注册量查询")
	@RequestMapping(value = "/dailyRegisteredUserVolume",method = RequestMethod.POST)
	public AjaxJson dailyRegisteredUserVolume(Integer time){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(
					operatorHomePageServiceInterface.dailyRegisteredUserVolume( time));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "用户商户量比", notes = "用户商户量比")
	@RequestMapping(value = "/userVolumeRatio",method = RequestMethod.POST)
	public AjaxJson userVolumeRatio(Integer time){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(
					operatorHomePageServiceInterface.userVolumeRatio( time));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "查询下单量统计==成交量统计   成交金额    优惠金额", notes = "查询下单量统计==成交量统计   成交金额    优惠金额")
	@RequestMapping(value = "/VolumeStatistics",method = RequestMethod.POST)
	public AjaxJson VolumeStatistics(){
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(
					operatorHomePageServiceInterface.VolumeStatistics());
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value = "查询成交量、金额趋势图", notes = "查询成交量、金额趋势图")
	@RequestMapping(value = "/VolumeSumMap",method = RequestMethod.POST)
	public AjaxJson VolumeSumMap(String strartTime,String endTime ){
		Date date1=null;
		Date date2=null;
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date1=format.parse(strartTime);
			date2=format.parse(endTime);
			ajaxJson.setSuccess(true).setStatus(200).setData(
					operatorHomePageServiceInterface.VolumeSumMap( date1, date2 ));
		} catch (ParseException e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("时间格式错误");
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(250).setData("查询失败");
		}
		return ajaxJson;
	}
	
}
